package st.business.tepth.business.user.busnumber.workholder.maintain.finish;

import java.util.List;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.MaintainPassInfoBean;
import st.business.tepth.business.user.busnumber.workholder.maintain.pass.MaintainPassDataConvert;

/**
 * @author zhangyu
 * @date 2019/4/19
 */
public class MaintainFinishPresenter extends MaintainFinishContract.Presenter {
    private final MaintainFinishContract.View mView;
    private final MaintainFinishContract.Model mModel;

    public MaintainFinishPresenter(MaintainFinishContract.View view) {
        mView = view;
        mModel = new MaintainFinishModel();
    }


    @Override
    void getData(String token, int repairId) {
        addDisposable(mModel.getData(token, repairId, new OnDataConvertListener<List<MaintainPassInfoBean>>() {
            @Override
            public void convert(List<MaintainPassInfoBean> list) {
                mView.showData(MaintainPassDataConvert.convertClassification(list));
            }

            @Override
            public void error(int code, String msg) {
                mView.showError(msg);
            }
        }));
    }


    @Override
    void checkPass(String token, int repairId, String repairTaskIds,
                   String reason, final int state) {
        addDisposable(mModel.checkPass(token, repairId, repairTaskIds,
                reason, state, new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        if (state == 0) {
                            mView.checkPassSucceed();
                        } else {
                            mView.checkNotPassSucceed();
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        mView.showError(msg);
                    }
                }));
    }

    @Override
    void cancelFinishWork(String token, int repairId) {
        addDisposable(mModel.cancelFinishWork(token, repairId,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        mView.cancelWorkSucceed();
                    }

                    @Override
                    public void error(int code, String msg) {
                        mView.showError(msg);
                    }
                }));
    }
}
